<template>
  <div>
    <div class="table-operator" v-if="stage !== '05010' && stage !== '05050'">
      <a-upload name="file"
                :showUploadList="false"
                :multiple="false"
                :data="queryParam"
                :headers="tokenHeader"
                :action="url.importExcelUrl"
                accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
                @change="handleImportExcel">
        <a-button type="primary"
                  style='background-color: #1EA489;border:0'>导入
        </a-button>
      </a-upload>
      <a-button type="primary"
                style='background-color: #FFA500;border:0' @click="OnExportList">
        导出
      </a-button>
      <a-button type="primary"
                style='background-color: #1A91B3;border:0'
                @click="OnExportTemp">
        模板下载
      </a-button>
<!--      <a-popconfirm title='确定取证吗?' @confirm="() => handelQz('取证')" :disabled="selectedRowKeys.length<=0">-->
      <a-button :disabled="selectedRowKeys.length<=0" @click="handelQz('取证')">
          取证
      </a-button>
<!--      </a-popconfirm>-->
    </div>
    <div v-if="stage !== '05010' && stage !== '05050'" class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
      selectedRowKeys.length }}</a>项&nbsp;&nbsp;
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="rowSelection">
      <span slot="actionName">
        <a-button v-if="stage !== '05010' && stage !== '05050'" size="small" @click="handleAdd('新增疑点')" type="primary" icon="plus">新增</a-button>
        <span v-else>操作</span>
      </span>
      <span v-if="stage !== '05010' && stage !== '05050'" slot="action" slot-scope="text, record">
        <a @click="handleEdit(record,'编辑疑点')">编辑</a>
        <template v-if="record.type != 2">
           <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </template>
      </span>
      <span slot="action" slot-scope="text, record" v-else>
        <a-button type="link" @click="handleCheck(record,'查看')">查看</a-button>
      </span>
    </a-table>
    <CheckAndEditModel ref="modalForm" :id="id" :bsjdwName="bsjdwName" :bsjdw="bsjdw" :type="type"
                       @ok="modalFormOk"></CheckAndEditModel>

    <QzModel ref="qzModalForm" :id="id" :bsjdwName="bsjdwName" :bsjdw="bsjdw" :protype="protype" :type="type"
                       @ok="modalFormOk"></QzModel>
  </div>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import CheckAndEditModel from './CheckAndEditModel'
  import {getAction, httpAction} from '@/api/manage'
  import columns from './indexColumns'
  import QzModel from '@views/sj/sjxmzygl/commView/sssj/sjyd/QzModel.vue'

  export default {
    props: ['id', 'bsjdwName', 'bsjdw', 'protype', 'type', 'stage'],
    name: "sjyd",
    components: {
      QzModel,
      CheckAndEditModel
    },
    mixins: [JeecgListMixin],
    data() {
      return {
        /* table选中keys*/
        selectedRowKeys: [],
        /* table选中records*/
        selectionRows: [],
        //表头
        queryParam: {
          proId: this.id,
          bsjdw: this.bsjdw
        },
        columns: columns(this),
        url: {
          list: '/sjxmzygl/sjWorkZtfaEveYidian/queryAuditDoubtfulPoint',
          delete: '/sjxmzygl/sjWorkZtfaEveYidian/remove',
          create: '/sjxmzygl/sjWorkZtfaEveYidian/turnYidianToProblemDigao',
          importExcelUrl: `${window._CONFIG['domianURL']}/sjxmzygl/sjWorkZtfaEveYidian/importExcel`,
          exportList: `/sjxmzygl/sjWorkZtfaEveYidian/exportDoubtfulPoint`,
          exportTemp: `${window._CONFIG['domianURL']}/sys/common/static/xls-template/ydxx.xlsx`
        }
      }
    },
    computed: {
      rowSelection() {
        return {
          selectedRowKeys: this.selectedRowKeys,
          onChange: (selectedRowKeys, selectedRows) => {
            this.selectedRowKeys = selectedRowKeys
            this.selectionRows = selectedRows
          },
          getCheckboxProps: record => ({
            props: {
              disabled: record.type == '2'
            }
          })
        }
      }
    },
    methods: {
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },

      handelQz(name){
        this.$refs.qzModalForm.addByYd(this.selectionRows,this.queryParam)
        this.$refs.qzModalForm.title = name
        this.$refs.qzModalForm.isCheck = false
        this.$refs.qzModalForm.disableSubmit = false
      },

      create() {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
        } else {
          var ids = this.selectedRowKeys.toString()
          getAction(this.url.create, {ids: ids}).then((res) => {
            if (res.success) {
              this.loadData()
              this.$message.success(res.message);
            } else {
              this.loadData()
              this.$message.warning(res.message);
            }
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>